package cn.wolfcode.wolf2w.cloud.msg.service.impl;

import cn.wolfcode.wolf2w.cloud.msg.service.ISmsRedisService;
import cn.wolfode.wolf2w.cloud.commom.util.RedisKeys;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class SmsRedisServiceimpl implements ISmsRedisService {

    @Autowired
    private StringRedisTemplate template;



    public void setVerifyCode(String phone, String code) {
        //String key= "verify_code:" + phone;
        String key = RedisKeys.VERIFY_CODE.join(phone);
        //参数1:key 参数2:value 参数3:时间, 参数4:时间单位
        template.opsForValue().set(key, code, RedisKeys.VERIFY_CODE.getTime(),
                TimeUnit.SECONDS);
    }

    public String getVerifyCode(String phone) {
        String key = RedisKeys.VERIFY_CODE.join(phone);
        return template.opsForValue().get(key);
    }
}
